#include "http/my_http_headers.h"
#include "comm/my_log.h"

void dump_header(my_http_header_t *header)
{
    MY_LOG_DEBUG("---------------------");
    my_http_header_dump(header);
}

void dump_headers(my_http_headers_t *headers)
{
    MY_LOG_DEBUG("----------------------");
    my_http_headers_dump(headers);
}

void dump_same_headers(my_http_same_headers_t *same_headers)
{
    MY_LOG_DEBUG("----------------------");
    my_http_same_headers_dump(same_headers);
}

void test_http_headers()
{
    my_pool_t *pool = my_pool_create();

    my_http_headers_t headers;
    bzero(&headers, sizeof(my_http_headers_t));
    my_http_headers_init(&headers, pool);

    my_str_t name1 = {.data = "name1", .len = sizeof("name1") - 1};
    my_str_t val1 = {.data = "val1", .len = sizeof("val1") - 1};
    my_http_header_t header1;
    bzero(&header1, sizeof(my_http_header_t));
    header1.name = name1;
    header1.value = val1;
    my_http_headers_add(&headers, &header1);

    my_str_t name11 = {.data = "nAMe1", .len = sizeof("nAMe1") - 1};
    my_str_t val11 = {.data = "val11", .len = sizeof("val11") - 1};
    my_http_header_t header11;
    bzero(&header11, sizeof(my_http_header_t));
    header11.name = name11;
    header11.value = val11;
    my_http_headers_add(&headers, &header11);

    my_str_t name2 = {.data = "name2", .len = sizeof("name2") - 1};
    my_str_t val2 = {.data = "val2", .len = sizeof("val2") - 1};
    my_http_header_t header2;
    bzero(&header2, sizeof(my_http_header_t));
    header2.name = name2;
    header2.value = val2;
    my_http_headers_add(&headers, &header2);

    my_str_t val22 = {.data = "val22", .len = sizeof("val22") - 1};
    my_http_header_t header22;
    bzero(&header22, sizeof(my_http_header_t));
    header22.name = name2;
    header22.value = val22;
    my_http_headers_add(&headers, &header22);

    my_str_t name3 = {.data = "name3", .len = sizeof("name3") - 1};
    my_str_t val3 = {.data = "val3", .len = sizeof("val3") - 1};
    my_http_header_t header3;
    bzero(&header3, sizeof(my_http_header_t));
    header3.name = name3;
    header3.value = val3;
    my_http_headers_add(&headers, &header3);

    dump_headers(&headers);

    my_http_header_t *header;
    header = my_http_headers_get(&headers, &name1);
    dump_header(header);

    my_http_same_headers_t *same_headers;
    same_headers = my_http_headers_values(&headers, &name1);
    dump_same_headers(same_headers);

    my_str_t name111 = {.data = "NaMe1", .len = sizeof("NaMe1") - 1};
    my_str_t val111 = {.data = "val111", .len = sizeof("val111") - 1};
    my_http_header_t header111;
    bzero(&header111, sizeof(my_http_header_t));
    header111.name = name111;
    header111.value = val111;
    my_http_headers_set(&headers, &header111);

    dump_headers(&headers);

    same_headers = my_http_headers_values(&headers, &name1);
    dump_same_headers(same_headers);

    my_http_headers_del(&headers, &header3);
    dump_headers(&headers);

    my_http_headers_del_by_name(&headers, &name2);
    dump_headers(&headers);

    my_pool_destroy(pool);
}

int main()
{
    test_http_headers();
    my_mem_assert_leak();

    MY_LOG_DEBUG("test pass");
    return 0;
}